﻿define(function (require) {
    var datacontext = require('modules/dataservice');
    var dialog = require('plugins/dialog');

    var vm = {
        customers: ko.observableArray(),
        order: ko.observable(),
        success: ko.observable(false),
        close: function () {
            var self = this;
            dialog.close(self, self.success());
        },
        activate: function (params) {
            var self = this;
            self.order(params);
            return datacontext.getCustomers(self.customers);
        },
        selectCustomer: function (customer) {
            vm.order().CustomerId(customer.Id());
            vm.success(true);
            vm.close();
        },
        deactivate: function () {
            var self = this;
            self.success(false);
        }
    };
    return vm;
});